/*ParallelPlatform Project - A web platform to distribute and share knowledge
Copyright (C) 2011  Daniel Guerrero Martinez & Sergio Rodriguez Lumley

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.*/


$(document).ready(function(){
	
	$(".multiImg").after(jQuery('<div class="selection"></div>'));
	
	$.each($(".multiImg").find("img"),function(){
		var img = $(this);
		var button = jQuery("<span></span>");
		button.click(function(){
			//img.parent().find("img").css("display","none");
			//img.css("display","block");
			img.parent().animate({width: img.width(),
				 				height: img.height()});
			img.parent().find("img[selected=selected]").fadeOut('fast', function(){
				$(this).removeAttr("selected");
				img.fadeIn('fast');
				img.attr('selected', 'selected');
			});
			
			img.parent().next().find("span").removeClass();
			$(this).addClass("selected");
		});
		img.parent().next().append(button);
	});
	$(".selection > span:first-child").addClass("selected");
	$(".multiImg > img:first-child").attr('selected', 'selected');
	
	$.each( $(".multiImg"), function(){
		if( $(this).attr("animate") ){
			$(this).click(function(){
				var animate = $(this).attr("animate");
				var ext = String(animate).split('.');
				ext = ext[ext.length-1].toLowerCase()
				
				var	param = ""
				var player = "/media/flash/online_player.swf"
				if( ext == "plpanim" )
					var	param = "file="+animate;
				else if( ext == "swf" )
					player = animate;
				
				var flash = jQuery('<div class="totalPanel"><div class="dialogPanel">'+
						   '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="700" height="500" id="online_editor" align="middle">'+
				           '<param name="allowScriptAccess" value="sameDomain" />'+
				           '<param name="allowFullScreen" value="false" />'+
				           '<param name="flashVars" value="'+param+'" />'+
				           '<param name="movie" value="'+player+'" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />'+
				           '<embed src="'+player+'" quality="high" bgcolor="#ffffff" width="700" height="500" name="online_editor" align="middle" '+
				           'flashVars="'+param+'" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer_es" />'+
				           '</object>'+
				           '</div></div>');
				           
				flash.click(function(){
					$(this).remove();
				});
				
				$("body").append(flash);
				
			});
		}
	});

});




